﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Kokomo.Mirror.CliMetadata.Signatures
{
	class ArrayShape : SignatureElement
	{
		public int rank;
		public int[] sizes;
		public int[] lowerBounds;

		public override string ToString()
		{
			StringBuilder builder = new StringBuilder();
			builder.Append("[");
			for (int i = 0; i < this.rank; i++)
			{
				if (i > 0) builder.AppendFormat(",");
				builder.AppendFormat("{0}-{1}", this.lowerBounds[i], this.sizes[i] + this.lowerBounds[i] - 1);
			}
			builder.AppendFormat("]");

			return builder.ToString();
		}

		public override bool Equals(object obj)
		{
			ArrayShape other = obj as ArrayShape;
			if (other == null) return false;

			bool equals =
				(this.rank == other.rank)
				&& (this.sizes != null)
				&& (other.sizes != null)
				&& (this.lowerBounds != null)
				&& (other.lowerBounds != null)
				&& (this.sizes.SequenceEqual(other.sizes))
				&& (this.lowerBounds.SequenceEqual(other.lowerBounds))
				;

			return equals;
		}
		public override int GetHashCode()
		{
			int hash = this.rank;

			return hash;
		}
	}
}
